home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / Cineol (+Culturalia) (ES).ifs < prev    next >
Text File  |  2005-05-27  |  15KB  |  465 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Icecubix
  8. Title=Cineol (+Culturalia) (ES)
  9. Description=Movie importation script for Cineol (picture from Culturalia).
  10. Site=http://www.cineol.com + http://www.culturalianet.com
  11. Language=ES
  12. Version=1.0
  13. Requires=3.5.0
  14. Comments=La imagen la coje de Culturalia mediante Culturalia+IMDB.ifs, ya que es mucho mas grande y hay muchφsimas. Hay c≤digo del script de FilmAffinity (ES).ifs. Los autores de ambos son David Arenillas, Antoine Potten and J.M. Folgueira, de Culturalia+IMDB.ifs y aviloria  (aviloria@yahoo.com) de FilmAffinity (ES).ifs
  15. License=The source code of the script can be used in another program only if full credits to script author and a link to Ant Movie Catalog website are given in the About box or in the documentation of the program.
  16. GetInfo=1
  17.  
  18. [Options]
  19. BuscarCaratula=1|1|0=Solo busca informaci≤n en CINEOL|1=Tambien busca la carßtula en CULTURALIA
  20. ModoBatch=0|0|0=Modo normal|1=Modo automßtico (batch). No pregunta nada ni muestra mensajes
  21.  
  22. ***************************************************)
  23.  
  24. program Cineol;
  25.  
  26. uses
  27.   StringUtils1;
  28.  
  29. const
  30.   BaseURLCulturalia = 'http://www.culturalianet.com/bus/catalogo.php';
  31.   BaseURLCineol = 'http://www.cineol.net/pelicula.php?action=';
  32.   BaseURLCineol2 = 'http://www.cineol.net/multisearch.php';
  33.  
  34. var
  35.   MovieName: string;
  36.   MovieURL: string;
  37.   Title: string;
  38.   i: integer;
  39.   s11: string;
  40.   buscarCaratulas: string;
  41.   preguntarTitulo: string;
  42.   minicaratula: string;
  43.   BuscarCaratula, ModoBatch: Boolean;
  44.   Page: TStringList;
  45.  
  46. //------------------------------------------------------------------------------------
  47.  
  48. function MiTextBetween(var S: string; StartTag: string; EndTag: string): string;
  49. var
  50.   InitialPos: Integer;
  51.   a,b: string;
  52. begin
  53.   a := ansiLowerCase(StartTag);
  54.   b := AnsiLowerCase(S);
  55.  
  56.   InitialPos := Pos(AnsiLowerCase(StartTag), AnsiLowerCase(S));
  57.   Delete(S, 1, InitialPos + Length(StartTag) - 1);
  58.   InitialPos := Pos(AnsiLowerCase(EndTag), AnsiLowerCase(S));
  59.   result := copy(S, 1, InitialPos - 1);
  60.   Delete(S, 1, InitialPos + 1);
  61. end;
  62.  
  63. //------------------------------------------------------------------------------------
  64.  
  65. function EliminaInicio(S: string; CR: string): string;
  66. begin
  67.   result := S;
  68.   while Pos(CR, result) = 1 do
  69.   begin
  70.     Delete(result, 1, Length(CR));
  71.   end;
  72. end;
  73.  
  74. function CadenaEntre(var S: string; StartTag: string; EndTag: string): string;
  75. var
  76.   InicioPos: Integer;
  77. begin
  78.   InicioPos := Pos(StartTag, S);
  79.   Delete(S, 1, InicioPos + Length(StartTag) - 1);
  80.   InicioPos := Pos(EndTag, S);
  81.   result := copy(S, 1, InicioPos - 1);
  82.   Delete(S, 1, InicioPos + 1);
  83. end;
  84.  
  85. procedure BuscarCaratulaCulturalia;
  86. var
  87.   strTemp: string;
  88.   Articles: array of string;
  89.   Index: integer;
  90. begin
  91.   SetArrayLength(Articles,11);
  92.   Articles[0]:='Lo ';
  93.   Articles[1]:='La ';
  94.   Articles[2]:='Le ';
  95.   Articles[3]:='Uno ';
  96.   Articles[4]:='Una ';
  97.   Articles[5]:='Un ';
  98.   Articles[6]:='El ';
  99.   Articles[7]:='Los ';
  100.   Articles[8]:='Las ';
  101.   Articles[9]:='Unos ';
  102.   Articles[10]:='Unas ';
  103.  
  104.   // Eliminate spanish article if exists
  105.   for Index := 0 to 10 do
  106.   begin
  107.    if Pos(Articles[Index], MovieName) <> 0 then
  108.    MovieName := copy(MovieName, length(Articles[Index]), length(MovieName));
  109.   end;
  110.  
  111.   // Eliminate point(s) at final of MovieName before search
  112.   strTemp := MovieName;
  113.   if Copy(strTemp, Length(strTemp), Length(strTemp)) = '.' then
  114.     MovieName := Copy(strTemp, 1, Length(strTemp) -1);
  115.    
  116.   AnalyzePageCulturalia(BaseURLCulturalia + '?catalogo=1&texto=' + UrlEncode(MovieName) + '&donde=1');
  117. end;
  118.  
  119. procedure AnalyzePageCulturalia(Address: string);
  120. var
  121.   Page, TempTit: TStringList;
  122.   LineNr: Integer;
  123.   Code, Title, TitleOrig, Year: string;
  124.   TitleFound: Boolean;
  125. begin
  126.   Page := TStringList.Create;
  127.   TempTit := TStringList.Create;
  128.   Page.Text := GetPage(Address);
  129.   Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  130.   if Pos('No se ha encontrado ning·n artφculo por tφtulo', Page.Text) = 0 then
  131.   begin
  132.     if not ModoBatch then
  133.     begin
  134.        PickTreeClear;
  135.        LineNr := 1;
  136.        PickTreeAdd('CULTURALIA: Imagenes para: "' + MovieName + '"', '');
  137.        while LineNr + 3 < Page.Count do
  138.        begin
  139.          Code := TextAfter(Page.GetString(LineNr), 'Codigo = ');
  140.          Title := TextAfter(Page.GetString(LineNr+1), 'Titulo = ');
  141.          TitleOrig := TextAfter(Page.GetString(LineNr+2), 'Titulo original = ');
  142.          Year := TextAfter(Page.GetString(LineNr+3), 'A±o = ');
  143.          PickTreeAdd(Title + ' (' + TitleOrig + '), ' + Year, BaseURLCulturalia + '?catalogo=1&codigo=' + Code);
  144.          LineNr := LineNr + 5;
  145.        end;
  146.        Page.Free;
  147.        if PickTreeExec(Address) then
  148.          AnalyzeMoviePageCulturalia(Address);
  149.     end else
  150.     begin
  151.       LineNr := 1;
  152.       TitleFound := True;
  153.       Code := TextAfter(Page.GetString(LineNr), 'Codigo = ');
  154.       Address := (BaseURLCulturalia + '?catalogo=1&codigo=' + Code);
  155.       if TitleFound then
  156.         AnalyzeMoviePageCulturalia(Address);
  157.       Page.Free;
  158.     end;
  159.   end else
  160.   if not ModoBatch then
  161.     ShowMessage('No se ha encontrado ninguna coincidencia por tφtulo');
  162. end;
  163.  
  164.  
  165. procedure AnalyzeMoviePageCulturalia(Address: string);
  166. var
  167.   Page: TStringList;
  168.   Comments: string;
  169.   strTitle: string;
  170.   strSinopsis: string;
  171.   Line: string;
  172.   LineNr: Integer;
  173.   strTemp: string;
  174. begin
  175.   Page := TStringList.Create;
  176.   Page.Text := StringReplace(GetPage(Address), '<br><br>', #13#10);
  177.   Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  178.   LineNr := FindLine('Imagen = ', Page, 0);
  179.   if LineNr <> -1 then
  180.      GetPicture(TextAfter(Page.GetString(LineNr), 'Imagen = '));
  181.   Page.Free;
  182. end;
  183.  
  184. procedure CINEOL_BuscarInformacion;
  185. var url: String;
  186.   Articles: array of string;
  187.   Index: integer;
  188. begin
  189.   SetArrayLength(Articles,11);
  190.   Articles[0]:='Lo ';
  191.   Articles[1]:='La ';
  192.   Articles[2]:='Le ';
  193.   Articles[3]:='Uno ';
  194.   Articles[4]:='Una ';
  195.   Articles[5]:='Un ';
  196.   Articles[6]:='El ';
  197.   Articles[7]:='Los ';
  198.   Articles[8]:='Las ';
  199.   Articles[9]:='Unos ';
  200.   Articles[10]:='Unas ';
  201.  
  202.   // Eliminate spanish article if exists
  203.   for Index := 0 to 10 do
  204.   begin
  205.    if Pos(Articles[Index], MovieName) = 1  then
  206.    MovieName := copy(MovieName, length(Articles[Index]), length(MovieName));
  207.   end;
  208.  
  209.   url := CINEOL_ListaBusqueda(BaseURLCineol2, URLEncode('search=' + MovieName + '&where=movies'));
  210.  
  211.   if url <> '' then
  212.     CINEOL_RecuperarInformacionPelicula(url);
  213. end;
  214.  
  215.  
  216. function CINEOL_ListaBusqueda(Address, params: String): string;
  217. var
  218.   Page, TempTit: TStringList;
  219.   LineNr: Integer;
  220.   Code, Title, tmp: string;
  221.   ini, fin, cont: integer;
  222.   encontradoParaBatch: boolean;
  223. begin
  224.   Page := TStringList.Create;
  225.   TempTit := TStringList.Create;
  226. // Hacemos un post. Hay otro metodo con get, pero si encuentra solo una hace un redireccionamiento raro
  227. // imposible de rastrear y perdo la pßgina.
  228.   Page.Text := PostPage(Address, params);
  229.  
  230.   Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  231.  
  232.   if Pos('>No se encontraron resultados<', Page.Text) = 0 then
  233.   begin
  234.        PickTreeClear;
  235.        PickTreeAdd('CINEOL: Resultados de b·squeda para: "' + MovieName + '"', '');
  236.        LineNr := FindLine('>Resultados de la b·squeda<', Page, 0);
  237.        if LineNr < 1 then
  238.          exit
  239.        else
  240.        begin
  241.          LineNr := LineNr + 4;
  242.          encontradoParaBatch := true; cont := 0;
  243.          while (pos('idpelicula=', Page.GetString(LineNr)) > 0) and (LineNr + 3 < Page.Count) do
  244.          begin
  245.            tmp   := TextAfter(Page.GetString(LineNr), 'idpelicula=');
  246.            Code  := copy(tmp, 1, pos('"', tmp)-1);
  247.  
  248.            ini := pos('">', tmp) + 2;
  249.            fin := pos('</a>', AnsiLowerCase(tmp)) - ini;
  250.            Title := copy(tmp, ini, fin);
  251.  
  252.            if ModoBatch and (AnsiLowerCase(Title) = AnsiLowerCase(MovieName)) then
  253.            begin
  254.              encontradoParaBatch := true;
  255.              Break;
  256.            end;
  257.  
  258.            PickTreeAdd(Title, BaseURLCineol + 'view&idpelicula=' + Code);
  259.            LineNr := LineNr + 1;
  260.            cont := cont + 1;
  261.          end;
  262.  
  263.          Page.Free;
  264.          if ModoBatch then
  265.          begin
  266.             if encontradoParaBatch or (cont  = 1) then
  267.               result := BaseURLCineol + 'view&idpelicula=' + Code
  268.          end
  269.          else
  270.          begin
  271.            if PickTreeExec(Address) then result := Address
  272.                                     else result := '';
  273.          end
  274.        end
  275.   end else
  276.   if not ModoBatch then
  277.     ShowMessage('CINEOL: No se ha encontrado ninguna coincidencia de "'+ MovieName +'"');
  278. end;
  279.  
  280. procedure CINEOL_RecuperarInformacionPelicula(Address: String);
  281. var
  282.   LineNr, aux: Integer;
  283.   Line, Line2: string;
  284.   Item, s_aux: string;
  285.   comentarios: string;
  286.   interpretes: string;
  287.   s: String;
  288. begin
  289.   // URL
  290.   SetField(fieldURL, Address);
  291.  
  292.   Page := TStringList.Create;
  293.   Page.Text := GetPage(Address);
  294.  
  295.   // Titulo traducido
  296.   s := buscaCampo('class="txPeliTit"', 0, '"txPeliTit">"', '" </TD>');
  297.   setField(fieldTranslatedTitle, s);
  298.  
  299.   // Titulo original
  300.   s := buscaCampo('>Tφtulo Original<', 0, 'Tφtulo Original</SPAN>: ', '<BR>');
  301.   setField(fieldOriginalTitle, s);
  302.  
  303.   // Genero/Categoria
  304.  
  305.   LineNr := FindLine('> GΘnero<', Page, 0);
  306.   if LineNr > 0 then
  307.   begin
  308.     Line := Page.GetString(LineNr);
  309.     if pos('title="', Line) > 0 then
  310.     begin
  311.       s := buscaCampo('> GΘnero<',         0,'title="', '"');
  312.       s := StringReplace(s, '/', ', ');
  313.     end
  314.     else
  315.       s := buscaCampo('> GΘnero<',         0,'GΘnero</SPAN>: ', '<');
  316.     setField(fieldCategory, s);
  317.   end;
  318.  
  319.   // Paφs
  320.   s := buscaCampo('>Paφs<',            0, 'Paφs</SPAN>: ', '<BR>');
  321.   setField(fieldCountry, s);
  322.  
  323.   // Duraci≤n
  324.   s := buscaCampo('>Duraci≤n<',        0, 'Duraci≤n</SPAN>: ', ' minutos');
  325.   setField(fieldLength, s);
  326.  
  327.   // Director
  328.   s := buscaCampo('>Direcci≤n<',      +1, '">', '<');
  329.   setField(fieldDirector, s);
  330.  
  331.   // Productor
  332.   s := buscaCampo('>Producci≤n<',     +1, '">', '<');
  333.   setField(fieldProducer, s);
  334.  
  335.   // Sinopsis
  336.   LineNr := FindLine('>Sinopsis<', Page, 0);
  337.   if LineNr > 0 then
  338.   begin
  339.     Item := copy(Page.Text, pos('Sinopsis</SPAN>:<BR>',Page.Text), length(Page.Text));
  340.     Item := MiTextBetween (Item, 'Sinopsis</SPAN>:<BR>', '<BR><BR>');
  341.     Item := StringReplace(Item, '<br>', #13#10);
  342.     Item := StringReplace(Item, '<BR>', #13#10);
  343.     HTMLDecode(Item);
  344.     SetField(fieldDescription, Trim (Item));
  345.   end;
  346.  
  347.   // A±o
  348.   s := buscaCampo('>A±o<',0, 'A±o</SPAN>: ', '<BR>');
  349.   setField(fieldYear, s);
  350.  
  351.   // Comentarios = Premios, Guion, fotografia, Musica, comentario destacado, web oficial
  352.   // Cada cual que se lo monte a su gusto. A mi me gusta asφ:
  353.   comentarios := '';
  354.   s := buscaCampo('>Premios<', 0, '>Premios</span>:<br>', '<');
  355.   if s <> '' then comentarios := comentarios + 'Premios: '#9#9 + s + #13#10;
  356.  
  357.   s := buscaCampo('>Gui≤n<',   +1, '">', '<');
  358.   if s <> '' then comentarios := comentarios + 'Gui≤n: '#9#9 + s + #13#10;
  359.  
  360.   s := buscaCampo('>M·sica<',  +1, '">', '<');
  361.   if s <> '' then comentarios := comentarios + 'M·sica: '#9#9 + s + #13#10;
  362.  
  363.   s := buscaCampo('>Fotografφa<', +1, '">', '<');
  364.   if s <> '' then comentarios := comentarios + 'Fotografφa: '#9 + s + #13#10;
  365.  
  366.   s := buscaCampo('>Web oficial:<', 0, 'href="', '"');
  367.   if s <> '' then comentarios := comentarios + 'Web oficial: '#9 + s + #13#10;
  368.  
  369.   s := '> Comentario destacado<';
  370.   LineNr := FindLine(s, Page, 0);
  371.   if LineNr > 0 then
  372.   begin
  373.     Item := copy(Page.Text, pos(s,Page.Text), length(Page.Text));
  374.     Item := MiTextBetween (Item, '<BR>', '</i></td></tr>');
  375.     Item := StringReplace(Item, '<br>', #13#10);
  376.     Item := StringReplace(Item, '<BR>', #13#10);
  377.     HTMLDecode(Item);
  378.     While pos(#13#10, Item) = 1 do Item := Copy(Item, 3, length(item)); //Nos comemos los <BR> iniciales
  379.     s := Trim(Item);
  380.     if s <> '' then
  381.     begin
  382.       comentarios := comentarios + ' _________________________________________________'#13#10;
  383.       comentarios := comentarios + #13#10 + 'COMENTARIO DESTACADO: ' + #13#10 + s + #13#10;
  384.     end
  385.   end;
  386.  
  387.   setField(fieldComments, comentarios);
  388.  
  389.   //Interpretes
  390.   interpretes := '';
  391.   LineNr := FindLine('>IntΘrpretes<', Page, 0) + 1;
  392.   Line := Page.GetString(LineNr);
  393.   While pos('gente.php?idperson', Line) > 0 do
  394.   begin
  395.     interpretes := interpretes + MiTextBetween (Line, '">', '</a>') + MiTextBetween (Line, '>', '<br') + #13#10;
  396.     LineNr := LineNr + 1;
  397.     Line := Page.GetString(LineNr);
  398.   end;
  399.   if interpretes <> '' then
  400.     SetField(fieldActors, interpretes);
  401.  
  402.   //Calificaci≤n
  403.   s := buscaCampo('images/iconotablanca.gif', 0, '<font size="1">', '<');
  404.   if s <> '' then setField(fieldRating, s);
  405.  
  406. end;
  407.  
  408. function buscaCampo(patron: String; offset: integer; ini, fin: string): String;
  409. var
  410.   LineNr: Integer;
  411.   Line: string;
  412.   Item: string;
  413. begin
  414.   Result := '';
  415.   LineNr := FindLine(patron, Page, 0);
  416.   if LineNr > 0 then
  417.   begin
  418.     LineNr := LineNr + offset;
  419.     Line := Page.GetString(LineNr);
  420.     Item := MiTextBetween (Line, ini, fin);
  421.     HTMLDecode(Item);
  422.     result := Trim(Item);
  423.   end;
  424. end;
  425.  
  426. //------------------------------------------------------------------------------------
  427. //------------------------------------------------------------------------------------
  428.  
  429.  
  430. begin
  431.   BuscarCaratula        := getOption('BuscarCaratula') <> 0;
  432.   ModoBatch             := getOption('ModoBatch') = 1; //OJO: SI EL TITULO DE
  433.                  //LA PELICULA NO COINCIDE NO MOSTRARA INFORMACI╙N, POR QUE LOS
  434.                  //RESULTADOS DE LA BUSQUEDA NO LOS ORDENA POR ORDEN DE SEMEJANZA
  435.  
  436.   { Un modo mas c≤modo de asignar las variables es marcando el check de la caratula y
  437.     del titulo traducido, en los "campos modificables". Si me desmarca la imagen no la buscarΘ
  438.     y si me marca el titulo traducido(por ejemplo) serα un proceso batch.:
  439.    
  440.     BuscarCaratula        := CanSetPicture();
  441.     ModoBatch             := not CanSetField(fieldTranslatedTitle);
  442.    }
  443.  
  444.   if CheckVersion(3,5,0) then
  445.   begin
  446.     MovieName := GetField(fieldTranslatedTitle);
  447.     if MovieName = '' then
  448.       MovieName := GetField(fieldOriginalTitle);
  449.      
  450.     if (MovieName = '') or not (ModoBatch) then
  451.       if not Input('Importar de CINeol + Culturalia', 'Introduzca el titulo de la pelicula:', MovieName) then
  452.         Exit;
  453.  
  454.     if (MovieName <> '') then
  455.     begin
  456.          CINEOL_BuscarInformacion; // El titulo a buscar siempre estß en MovieName
  457.  
  458.          if BuscarCaratula then
  459.             BuscarCaratulaCulturalia;
  460.     end;
  461.   end
  462.   else
  463.     ShowMessage('Este script requiere una version mas reciente de Ant Movie Catalog (por lo menos la version 3.5.0)');
  464. end.
  465.